package com.zbmsg.utils.id;

import java.util.Random;

/**
 * 通用id生成器
 * 
 * @author xujianxing
 *
 */
public class NormalIdUtil {

	/**
	 * 生成与用户相关的唯一编码
	 * 
	 * @param userId
	 * @param length
	 * @return
	 */
	public static String getRandomString(long userId, int length) {
		String base = "ab0c1d2e3f4g5h6i7j8k9lmnopqrstuvwxyz";
		String idStr = String.valueOf(userId);
		StringBuffer sb = new StringBuffer();
		char[] charrArray = idStr.toCharArray();
		for (char c : charrArray) {
			int number = Integer.valueOf(String.valueOf(c));
			sb.append(base.charAt(number));
		}
		Random random = new Random();
		int extlenth = length - idStr.length();
		if (extlenth > 0) {
			for (int i = 0; i < extlenth; i++) {
				int number = random.nextInt(base.length());
				sb.append(base.charAt(number));
			}
		}
		return sb.toString();
	}
	

	
}
